package com.hljx.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 手术申请表 前端控制器
 * </p>
 *
 * @author cw
 * @since 2023-10-31
 */
@RestController
@RequestMapping("/opApply")
public class OpApplyController {


    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    @Qualifier("opApplyJob")
    private Job sampleJob;

    @Operation(description = "手术")
    @GetMapping("/opApplyJob")
    public void opApplyJob() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
        JobParameters jobParameters = new JobParametersBuilder()
                .addLong("time",System.currentTimeMillis())
                .addString("startDate", "2024-01-01 00:00:00")
                .addString("endDate","2024-3-31 23:59:59")
                .addString("splitTableName","20241")
                .toJobParameters();
        jobLauncher.run(sampleJob, jobParameters);
    }


}
